<script language="javascript" type="text/javascript">
        $(document).ready(function(){
            $('#filter_button_date').click(function(){
                $('#adminForm').submit();
            });
            $( "#filter_end_date" ).datepicker({
                dateFormat: 'dd-mm-yy',
                changeMonth: true,
                changeYear: true,
                yearRange: '1900:2090'
            });
            $('#select_filter_end_date').click(function(){
                $( "#filter_end_date" ).datepicker('show');
            });
            $( "#filter_start_date" ).datepicker({
                dateFormat: 'dd-mm-yy',
                changeMonth: true,
                changeYear: true,
                yearRange: '1900:2090'
            });
            $('#select_filter_start_date').click(function(){
                $( "#filter_start_date" ).datepicker('show');
            });
        });
</script>
<div id="toolbar-box">
  <div class="t">
    <div class="t">
      <div class="t"></div>
    </div>
  </div>
  <div class="m">
    <div id="toolbar" class="toolbar">
      <table class="toolbar">
        <tbody>
          <tr>
            <td id="toolbar-delete" class="button"><a class="toolbar" onClick="javascript:if(document.adminForm.boxchecked.value==0){alert('Please select a User from the list to delete');}else{if(confirm('Are you sure you want to delete the listed Items?')){submitbutton('remove');}}" href="javascript:void(0);"> <span title="Delete" class="icon-32-delete"> </span> Delete </a></td>
          </tr>
        </tbody>
      </table>
    </div>
    <div class="header icon-48-user">Quản lý đơn đặt hàng</div>
    <div class="clr"></div>
  </div>
  <div class="b">
    <div class="b">
      <div class="b"></div>
    </div>
  </div>
</div>
<?php echo $this->Session->flash('msg'); ?>
<div id="submenu-box">
  <div class="t">
    <div class="t">
      <div class="t"></div>
    </div>
  </div>
  <div class="m">
    <ul id="submenu">
      <li> <a class="active" href="<?php echo $this->Html->url(array('controller'=>'orders', 'action'=>'index')); ?>">Quản lý đơn đặt hàng</a> </li>
      <li> <a href="<?php echo $this->Html->url(array('controller'=>'transport_fee', 'action'=>'index')); ?>">Phí vận chuyển</a> </li>
      <li> <a href="<?php echo $this->Html->url(array('controller'=>'reports', 'action'=>'index')); ?>">Báo cáo doanh thu</a> </li>
    </ul>
    <div class="clr"></div>
  </div>
  <div class="b">
    <div class="b">
      <div class="b"></div>
    </div>
  </div>
</div>
<div id="element-box">
  <div class="t">
    <div class="t">
      <div class="t"></div>
    </div>
  </div>
  <div class="m">
    <form action="<?php echo $this->Html->url(array('controller'=>'orders')); ?>" method="post" id="adminForm" name="adminForm">
      <table width="100%">
        <tr>
          <td width="15%"><input type="text" name="search" id="search" class="text_area" value="<?php echo $keyword;?>"/>
            <button onClick="document.adminForm.limitstart.value=0; document.adminForm.submit();">Go</button>
            </td>
            <td width="25%">
                Fiter: <?php 
                            echo $this->Form->select('order_status',$order_status, array('empty'=>false, 'value'=> $order_status_selected, 'onchange' => 'order_filter_status();'));
                            echo $this->Form->select('payment_status',$payment_status, array('empty'=>false, 'value'=> $order_payment_status_selected, 'onchange' => 'order_filter_status();'));
                        ?>
            </td>
            <td width="65%">
                Start: <input type="text" name="filter_start_date" id="filter_start_date" class="text_area" value="<?php echo $filter_start_date;?>"/>
                <a href="javascript:void(0);" id="select_filter_start_date">
                    <?php echo $this->Html->image('ico_calendar.gif'); ?>
                </a>
                end: <input type="text" name="filter_end_date" id="filter_end_date" class="text_area" value="<?php echo $filter_end_date;?>"/>
                <a href="javascript:void(0);" id="select_filter_end_date">
                    <?php echo $this->Html->image('ico_calendar.gif'); ?>
                </a>
                <button id="filter_button_date"/>Go</button>
                <button onClick="document.adminForm.filter_start_date.value='';document.adminForm.filter_end_date.value=''; document.adminForm.search.value=''; document.adminForm.submit();">Clear</button>
            </td>
        </tr>
      </table>
      <table class="adminlist">
        <thead>
          <tr>
            <th width="5%"> Num </th>
            <th width="5%"> <input type="checkbox" name="toggle" value=""  onclick="checkAll(<?php echo $total;?>);" />
            </th>
            <th class="title"> <?php echo $this->Paginator->sort('id', 'Mã hóa đơn'); ?> </th>
            <th class="title"> <?php echo $this->Paginator->sort('created', 'Ngày đặt hàng'); ?> </th>
            <th class="title"> <?php echo $this->Paginator->sort('total_price', 'Tổng tiền'); ?> </th>
            <th><?php echo $this->Paginator->sort('payment_status', 'Tình trạng thanh toán'); ?></th>
            <th><?php echo $this->Paginator->sort('transport_status', 'Tình trạng giao hàng'); ?></th>
            <th>Chi tiết</th>
          </tr>
        </thead>
        <tfoot>
          <tr>
            <td colspan="8"><?php echo $this->element('paging', array('paging'=>$this->Paginator));?></td>
          </tr>
        </tfoot>
        <tbody>
          <?php
				$tr_class = 0;
                                $i = ($start_page - 1) * $limit_page;
				if($total)
				{
					foreach ($data as $row)
					{
                                            $tr_class = 1 - $tr_class;
				?>
          <tr class="row<?php echo $tr_class;?>">
            <td align="center"><?php echo $i + 1;?></td>
            <td align="center">
                <input id="cb<?php echo $i; ?>" onclick="isChecked(this.checked);" type="checkbox" name="cid[]" value="<?php echo $row['Order']['id']; ?>" />
            </td>
            <td><?php echo 'H3L' . str_pad($row['Order']['id'], 5, "0", STR_PAD_LEFT); ?></td>
            <td><?php echo $row[0]['created']; ?></td>
            <td align="center"><?php echo number_format(sprintf("%01.2f", $row['Order']['total_price']),0, ',', '.');?></td>
            <td align="center"><?php echo $payment_status[$row['Order']['payment_type']];?></td>
            <td align="center"><?php echo $order_status[$row['Order']['transport_status']];?></td>
            <td align="center"><a href="<?php echo $this->Html->url(array('controller'=>'orders', 'action'=>'edit', 'id'=>$row['Order']['id'])); ?>">Xem chi tiết</a></td>
          </tr>
          <?php
                                    $i++;
					}
				}
				else
				{
				?>
          <tr>
            <td align="center" colspan="8"> No contents </td>
          </tr>
          <?php
				}
				?>
        </tbody>
      </table>
      <input type="hidden" name="task" value="index" />
      <input type="hidden" name="boxchecked" value="0" />
      <?php echo $this->FORM_TOKEN;?>
    </form>
    <div class="clr"></div>
  </div>
  <div class="b">
    <div class="b">
      <div class="b"></div>
    </div>
  </div>
</div>

